
class Animals {
    public String name;
    public int age;
    public Animals(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat() {
        System.out.println(name + "正在吃");
    }
    @Override
    public String toString() {
        return "Animals{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

}
class Dog extends Animals {
    public Dog(String name, int age) {
        super(name, age);
    }
    public void wangWang() {
        System.out.println(name+"正在汪汪");
    }
    @Override
    public void eat() {
        System.out.println(name+"正在吃狗粮");
    }
}
class Bird extends Animals {
    public Bird(String name, int age) {
        super(name, age);
    }
    public void fly (){
        System.out.println(name+"正在飞");
    }
}
//1.直接赋值
public class Test {
    public static void main(String[] args) {
        Animals animal1 = new Dog("小狗",10);//父类引用引用子类对象，向上转型
        animal1.eat();//小狗正在吃狗粮
        Bird bird1 = new Bird("小鸟",10);
        func1(bird1);
        Animals animal2 = new Bird("大鸟",20);
        Bird bird2 = (Bird)animal2;//向下转型， 不安全
        bird2.fly();
    }
    //2.方法传参
    public static void func1(Animals animal) {//父类可以接受子类
    }
    //3.返回值
    public static Animals func2() {
        return new Bird("小鸟",10);
    }
}
